﻿Imports EguSoc_Dll

Public Class FES_Articulos
    Private TA_Articulos As New ArticulosTableAdapter
    Private TA_Articulos_Compuestos As New Articulos_Compuestos
    Private TA_Articulos_Tipo As New DSEATableAdapters.Tipo_ArticulosTableAdapter
    Private TA_ArticulosAux As New ArticulosTableAdapter

    Private Sub FEA_Articulos_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            TA_Articulos_Tipo.FillByDefineArticulo(DSEA.Tipo_Articulos)
            TA_ArticulosAux.Fill(DSAux.Articulos)
            TA_Articulos.Fill(DSEA.Articulos)
            TA_Articulos_Compuestos.Fill(DSEA.Articulos_Compuestos)

            Muestra_Controles(TipoComboBox.SelectedValue)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ArticulosBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Call Grabar()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub Grabar()
        Try
            Me.Validate()
            Me.ArticulosBindingSource.EndEdit()
            TA_Articulos.Grabar(DSEA.Articulos)

            DescripcionTxtBoxAlfa.Focus()
            'TA_Articulos_Compuestos.Grabar(DSEA.Articulos_Compuestos)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ImagenPictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImagenPictureBox.Click
        Try
            If OFDImagen.ShowDialog = DialogResult.OK Then
                Dim imagen As New Bitmap(New Bitmap(OFDImagen.FileName), ImagenPictureBox.Width, ImagenPictureBox.Height)
                ImagenPictureBox.Image = imagen
            End If
        Catch ex As Exception

        End Try

    End Sub

    Private Sub ToolStripExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            If DSEA.HasChanges Then
                Select Case MessageBox.Show("¿Desea guardar antes de salir?", "Txerri Aska", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information)
                    Case vbNo
                        Me.Close()
                    Case vbYes
                        Grabar()
                        Me.Close()
                    Case Else
                        Exit Sub
                End Select
            Else
                Me.Close()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub TipoComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TipoComboBox.SelectedIndexChanged
        Try
            Muestra_Controles(TipoComboBox.SelectedValue)
            TipoComboBox.EndUpdate()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ToolStripExit_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub GuardarToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GuardarToolStripButton.Click
        Try
            Call Grabar()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Me.Close()
    End Sub

    Private Sub Muestra_Controles(ByVal index As Integer)
        Try
            Tbl_Articulos_CompuestosDataGridView.Visible = False
            Select Case index
                Case 2 ''Refrescos,Cervezas 
                    PVCopa.Visible = False
                    PVTapon.Visible = False
                Case 3 ''Copas,Combinados y Combinados Especial 
                    PVCopa.Visible = True
                    PVTapon.Visible = True
                Case 1 ''Cafés y Otros
                    PVCopa.Visible = False
                    PVTapon.Visible = False
                    'Tbl_Articulos_CompuestosDataGridView.Visible = True
                Case 4 ''Vinos y Mosto
                    PVCopa.Visible = True
                    PVTapon.Visible = False
            End Select
        Catch ex As Exception

        End Try
    End Sub

End Class